<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Layui</title>
    <link rel="stylesheet" type="text/css" href="../static/layui/css/layui.css">
    <script type="text/javascript" src="../static/js/jquery-3.3.1.min.js"></script>
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
    <style>
        /*鼠标放上小手标志*/
        font {
            cursor: pointer;
        }
    </style>
</head>
<body>
<div class="demoTable" style="position: absolute;z-index: 1000 ;margin-top: 5px;">
    <form>
        <select id="itemsState" style="width: 80px;height: 38px;border-color: #efefef;">
            <option value="">类别</option>
            <option value="1">通知</option>
            <option value="2">政策</option>
            <option value="3">公示</option>
        </select>
        <select id="itemsDepartments" name="itemsDepartments" style="width: 180px;height: 38px;border-color: #efefef;">
            <option value="">部门</option>
        </select>

        <div class="layui-inline">
            <input class="layui-input" name="demoReload" id="demoReload" autocomplete="off" placeholder="请输入关键词">
        </div>
        <button class="layui-btn" data-type="reload" id="reload">查询</button>
        <div class="layui-input-inline">
            <input type="reset" class="layui-input"
                   style="width: 60px;height: 38px;text-align: center;background-color:#16c4ff;color: white ">
        </div>
    </form>
</div>
<script type="text/html" id="zizeng">
    {{d.LAY_TABLE_INDEX+1}}
</script>
<table class="layui-hide" id="test" lay-filter="test"></table>



<!-- 操作指令 -->
<script type="text/html" id="barDemo">

    {{#  if(d.circular_hot== "1"){ }}
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="edit" style="color: blue">设为热门</a>
    {{#  } }}
    {{#  if(d.circular_hot== "0"){ }}
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="allat" style="color: red">取消热门</a>
    {{#  } }}

</script>


<script src="../static/layui/layui.js"></script>
<!-- 注意：如果你直接复制所有代码到本地，上述 JS 路径需要改成你本地的 -->

<script>
    layui.use('table', function () {
        var table = layui.table;
        // var circularId ='';
        table.render({
            elem: '#test',
            url: 'hotspot',
            // where: {circularId :circularId},
            toolbar: '#toolbarDemo',
            defaultToolbar: ['exports'],
            title: '热点配置表',

            id: 'testReload',
            cols: [
                [ {
                    field: 'zizeng',
                    width: 210,
                    title: '序号',
                    templet: '#zizeng',
                    hide: true
                }, {
                    field: 'circular_id',
                    title: 'ID',
                    hide: true
                }, {
                    field: 'circular_title',
                    title: '标题',
                    align: 'center'
                },{
                    field: 'department_name',
                    title: '部门',
                    width: 250,
                    align: 'center'
                }, {
                    field: 'project_name',
                    title: '项目',
                    width: 250,
                    align: 'center'
                }, {
                    field: 'circular_date',
                    title: '日期',
                    width: 309,
                    align: 'center'
                }, {
                    field: 'circular_hot',
                    title: '状态',
                    width: 210,
                    // id:"abc"
                    toolbar: '#barDemo',
                    align: 'center'
                    // sort: true
                }]
            ],
            page: { //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
                layout: ['count', 'prev', 'page', 'next', 'limit', 'skip']//自定义分页布局
                , first: false //不显示首页
                , last: false //不显示尾页
            },
            height: 550,
            done: function (res, curr, count) {
            }
        });



        // 模糊查询 搜索
        var $ = layui.$, active = {
            reload: function () {
                var itemsState = $('#itemsState').val();
                // var itemsObjname = $('#itemsObjname').val();
                var itemsDepartments = $('#itemsDepartments').val();
                var circularCreatetime = $('#userCreateTime').val();
                var circularFinishtime = $('#userFinishTime').val();
                var demoReload = $('#demoReload').val();
                //执行重载
                table.reload('testReload', {
                    page: {
                        curr: 1 //重新从第 1 页开始
                    },
                    where: {
                        itemsState: itemsState,
                        // itemsObjname: itemsObjname,
                        deSelect: itemsDepartments,
                        circularCreatetime: circularCreatetime, //逗号隔开
                        circularFinishtime: circularFinishtime,
                        demoReload: demoReload
                    }
                });
            }
        };
        //提交
        $('.demoTable .layui-btn').on('click', function (e) {
            e.preventDefault();
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });



        //分页挪到右下角
        // $('.layui-table-page').css('text-align', 'right');
        //工具栏事件
        table.on('toolbar(test)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id);
            switch (obj.event) {
                case 'getCheckLength':
                    var data = checkStatus.data;
                    layer.msg('选中了：' + data.length + ' 个');
                    break;
                case 'edit':
                    layer.msg(obj.data.circularId)
                    break;
                case 'allat':
                    layer.msg(obj.data.circularId)
                    break;
            }
            ;
        });
        // 监听行工具事件
        table.on('tool(test)', function (obj) {
            var data = obj.data;
            //取消热门
            if (obj.event == 'allat'){
                var flag = confirm("您确定要取消热门吗？")
                if (flag) {
                    $.ajax({
                        url: "/cancel",
                        async: true,
                        type: "post",
                        data: {circularId: data.circular_id},
                        dataType: "json",
                        success: function (data) {
                            if (data == "200") {
                                alert("修改成功")
                                window.location.href = "/hotspotjump";
                                // window.open("/success.jsp")
                            } else {
                                alert("修改失败，请重新修改")
                                // window.location.href = "NotSuccess.jsp"
                            }
                        }
                    })
                }

            }

            //设为热门
            if (obj.event == 'edit') {
                var flag = confirm("您确定要设为热门吗？")
                if (flag) {
                    $.ajax({
                        url: "/setup",
                        async: true,
                        type: "post",
                        data: {circularId: data.circular_id},
                        dataType: "json",
                        success: function (data) {
                            if (data == "200") {
                                alert("修改成功")
                                window.location.href = "/hotspotjump";
                                // window.open("/success.jsp")
                            } else {
                                alert("修改失败，请重新修改")
                                // window.location.href = "NotSuccess.jsp"
                            }
                        }
                    })
                }
            }

         });
    });

</script>
<script>
    //日期范围
    layui.use('laydate', function () {
        var laydate = layui.laydate;
        //日期时间选择器
        laydate.render({
            elem: '#userCreateTime'
            ,type: 'date'
        });
        laydate.render({
            elem: '#userFinishTime'
            ,type: 'date'
        });
    });




        //部门
    layui.use('form', function () {
        var $ = layui.jquery;
        var form = layui.form;
        //地区
        $.ajax({
            url: '/selDe',
            dataType: 'json',
            type: 'post',
            success: function(data) {
                if (data!== null) {
                    $("#itemsDepartments").empty();
                    $("#itemsDepartments").append(new Option("请选择部门", ""));
                    $.each(data, function(index, item) {
                        var domo = item.departmentName
                        $('#itemsDepartments').append(new Option(JSON.stringify(domo).replace(/\"/g, "")));
                    });
                } else {
                    $("#itemsDepartments").append(new Option("暂无数据", ""));
                }
                //重新渲染
                form.render("#itemsDepartments");
            }
        });
    })

</script>
</body>
</html>
